﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reborn_Server.App1AppHandler;
using App1AppHandler;

namespace Reborn_Server.App1AppHandler
{
    public class Spell_ExcessiveForce : Buff
    {
        public Spell_ExcessiveForce() : base() { }

        private int numUses = 1;
        private int currentUses = 0;

        public double GetMultiplier()
        {
            currentUses++;

            if (currentUses == numUses)
                RemoveSpell(true, true);

            if (spellIcon.Name == "Furious Rush")
                return 1.3;
            else if (spellIcon.Name == "Beserker Frenzy")
                return 1;

            else return 1;
        }

        public override bool castWhileAlone(SpellIcon sIcon)
        {
            return true;
        }

        public override int GetOptionalValue()
        {
            return currentUses;
        }

        override public void Resume(CreatureBase targetCreatureBase, SpellIcon _spellIcon, int timeRemaining, int castLevel, int castCharacterID, int castInt, int castWis, int optionalValue, string xmlData)
        {
            minutesLeft = timeRemaining;
            base.Resume(targetCreatureBase, _spellIcon, timeRemaining, castLevel, castCharacterID, castInt, castWis, optionalValue, xmlData);

            if (spellIcon.Name == "Beserker Frenzy")
                numUses = (castLevel / 3);
            else
                numUses = 3 + (castLevel / 2);

            currentUses = optionalValue;

            spellTimer.Start();
        }
        public void Cast(CreatureBase myCreatureBase, int CastLevel, long CreatureGUID)
        {
            List<MapItem> MapItemsWithin12;
            if (base.InitializeCast(myCreatureBase, CastLevel, CreatureGUID, true, out MapItemsWithin12) == false)
                return;

            minutesLeft = CastingCreatureWis / 2;

            if (spellIcon.Name == "Beserker Frenzy")
                numUses = (CastLevel / 3);
            else
                numUses = 3 + (CastLevel / 2);

            TargetCreatureBase.buffManager.UpdateBuffs();

            foreach (MapItem mapitem in MapItemsWithin12)
            {
                if (Math.Abs(mapitem.MapX - TargetCreatureBase.MapX) <= 8 && Math.Abs(mapitem.MapY - TargetCreatureBase.MapY) <= 8)
                {
                    foreach (CreatureBase creaturebase in mapitem.CreaturesBases)
                    {
                        if (creaturebase is Character)
                        {
                            Character character = (Character)creaturebase;
                            character.PlaySound("BuffCast", TargetCreatureBase.MapX, TargetCreatureBase.MapY);
                        }
                    }
                }
            }

            //Start Spell Timer
            spellTimer.Start();
        }
    }
}
